import { UploadApiResult } from './model/uploadModel';
import { defHttp } from '/@/utils/http/axios';
import {ErrorMessageMode, UploadFileParams} from '/#/axios';
import { useGlobSetting } from '/@/hooks/setting';
import {LoginParams, LoginResultModel} from "/@/api/sys/model/userModel";
import {ContentTypeEnum} from "/@/enums/httpEnum";

const { uploadUrl = '' } = useGlobSetting();

/**
 * @description: Upload interface
 */
export function uploadApi(
  params: UploadFileParams,
  onUploadProgress: (progressEvent: ProgressEvent) => void,
) {
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: "/excel",
      onUploadProgress,
    },
    params,
  );
}

/**
 * @description: Upload interface
 */
export function uploadCommonApi(params: any, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: uploadUrl,
      headers: {
        'Content-type': ContentTypeEnum.FORM_DATA,
        // @ts-ignore
        ignoreCancelToken: true,
      },
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
